#include "bsp_IrRemote.h"
#include "tim.h"
#include "bsp_Led.h"

void bsp_IrRemote::sendCallBack(BSP_TIM_Handle_t *htim)
{
    if (htim->Instance == TIM->Instance)
    {
        QUEUE_DATA_T temp = 0;
        if (pop(&temp) == QUEUE_OK)
        {
            if (temp == 1)
            {
                setCompare(PERIOD);
            }
            else
            {
                setCompare(0);
            }
        }
        else
        {
            setCompare(0);
            BSP_TIM_PWM_Stop_IT(TIM, Channel);
        }
    }
}

void bsp_IrRemote::Send(QUEUE_DATA_T *buff, int size)
{
    pushArray(buff, size);
    BSP_TIM_PWM_Start_IT(TIM, Channel);
}

#if DEMO_IRREMOTE
bsp_IrRemote demoIrRemote(&htim3, TIM_CHANNEL_1);
#endif
